﻿<!DOCTYPE HTML>
<html>
<head>
    <!--作为公共模版分离出去-->
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui/css/H-ui.my.css" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui.admin.pro.iframe/css/h-ui.admin.pro.iframe.min.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/Hui-iconfont/1.0.9/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui.admin.pro.iframe/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="admin/lib/jquery-easyui/1.7.0/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/jquery-easyui/1.7.0/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/lc_switch/20160127/css/lc_switch.css" />
    <link rel="stylesheet" type="text/css" href="admin/css/mywork.css" />
    <script type="text/javascript" src="admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="admin/lib/layer/3.1.1/layer.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/plugins/datagrid-detailview.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="admin/lib/lc_switch/20160127/js/lc_switch.min.js"></script>
    <script>document.write('<script type="text/javascript" src="admin/js/common.js?v='+ Date.now() +'"><\/script>');</script>
    <script>document.write('<script type="text/javascript" src="admin/js/formatter.js?v='+ Date.now() +'"><\/script>');</script>
    <!--作为公共模版分离出去-->
    <title>${tableDesc}列表</title>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%;font-family: 微软雅黑" memuId="${objectName?uncap_first}-list">
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en" style="float: none">&gt;</span> ${tableDesc}管理
    <span class="c-gray en" style="float: none">&gt;</span> ${tableDesc}列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<!--按钮元素-->
<div id="buttonInfo" class="buttonInfo">
    <button class="easyui-linkbutton" onclick="add${objectName}()"><i class="Hui-iconfont">&#xe600;</i>新增</button>
    <button class="easyui-linkbutton" onclick="edit${objectName}()"><i class="Hui-iconfont">&#xe6df;</i>修改</button>
    <button class="easyui-linkbutton" onclick="del${objectName}()"><i class="Hui-iconfont">&#xe6e2;</i>删除</button>
</div>
<!--查询条件元素-->
<div id="searchInfo" class="searchInfo">
<#list entityList as entity>
    <#if entity.isSearch=="Y">
    <div class="searchLabel">${entity.keyNote}：<span id="s_${entity.keyName}"></span></div>
    </#if>
</#list>
    <a id="searchBtn" onclick="query(pageParam, true)"></a>
</div>
<!--表格元素-->
<div id="tableInfo"></div>
<script type="text/javascript">
    //准备函数
    $(function () {
        initSearchForm();
        initGrid();
        getGridHidden("tableInfo");
        query(pageParam);
    });

    //查询条件初始化
    function initSearchForm() {
<#list entityList as entity>
    <#if entity.isSearch=="Y">
        $("#s_${entity.keyName}").textbox({
            width: 150,
            prompt: "请输入${entity.keyNote}"
        });
    </#if>
</#list>
        $("#searchBtn").linkbutton({
            text: '查询',
            plain: "true",
            iconCls: 'icon-search'
        });
    }

    //表格元素初始化
    function initGrid() {
        $("#tableInfo").datagrid({
            pagination: true,
            singleSelect: false,
            fitColumns: true,
            striped: true,
            fit: true,
            columns: [[
                {field: "ck", checkbox: "true"},
                {field: "id", title: "编号", width: 60, align: "center", sortable: true},
    <#list entityList as entity>
        <#if entity.isShow=="Y">
            <#if entity.isSort=="Y">
                {field: "${entity.keyName}", title: "${entity.keyNote}", width: 100, align: "center", sortable: true}<#if entity_has_next>,</#if>
            <#else>
                {field: "${entity.keyName}", title: "${entity.keyNote}", width: 100, align: "center"}<#if entity_has_next>,</#if>
            </#if>
        </#if>
    </#list>
            ]],
            //表格工具栏元素ID
            toolbar: ".breadcrumb, #buttonInfo, #searchInfo",
            onSortColumn: function (sort,order) {
                pageParam.pageNo = 1;
                pageParam.sort = sort;
                pageParam.order = order;
                query(pageParam);
            },
            onSelect: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onUnselect: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onSelectAll: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onUnselectAll: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onLoadSuccess: function (data) {
                toolBarBtnDisabledById([false, true, true], "buttonInfo");
            }
        });
        //表格事件
        var selectedTableRow = function() {
            var selectRow = $("#tableInfo").datagrid("getSelections");
            if (selectRow.length == 0) {
                toolBarBtnDisabledById([false, true, true], "buttonInfo");
            } else if (selectRow.length == 1) {
                toolBarBtnDisabledById([false, false, false], "buttonInfo");
            } else {
                toolBarBtnDisabledById([false, true, false], "buttonInfo");
            }
        };
        //表格分页
        var pager = $("#tableInfo").datagrid("getPager");
        pager.pagination({
            total: 0,
            rows: 0,
            pageNumber: pageParam.pageNo,
            pageSize: pageParam.pageSize,
            pageList: Page.getPageList(),
            buttons: [
				{text: "个性化设置", iconCls: "icon-tip", handler: function() {selectColumnMenu("tableInfo");}}
            ],
            onBeforeRefresh : function() {},
            onSelectPage: function(pageNumber, pageSize) {
                pageParam.pageNo = pageNumber;
                pageParam.pageSize = pageSize;
                query(pageParam);
            },
            onChangePageSize: function(pageSize) {
                pageParam.pageSize = pageSize;
            }
        });
    }

    //获取用户个性化设置
    function getGridHidden() {
        ajaxPostFun("userMenuHidden/getUserMenuHidden", {menu_id: $("body").attr("memuId"), grid_id: "tableInfo"}, function(bizData) {
            for (var i in bizData) {
                $("#tableInfo").datagrid("hideColumn", bizData[i].grid_col);
            }
        }, null, "获取用户个性化设置");
    }

    //分页查询
    function query(pageParam, goHead) {
<#list entityList as entity>
    <#if entity.isSearch=="Y">
        pageParam.${entity.keyName} = $("#s_${entity.keyName}").textbox("getValue").trim();
    </#if>
</#list>
        if (goHead && goHead)
            pageParam.pageNo = 1;
        var successFun = function(bizData) {
            $("#tableInfo").datagrid("loadData", bizData.rows);
            $("#tableInfo").datagrid("getPager").pagination({pageNumber: bizData.page, total: bizData.records});
        };
        var errorFun = function() {
            showFailedMsg("查询数据出错");
        };
        ajaxGetFun("${objectName?uncap_first}/queryPage", pageParam, successFun, errorFun, "获取${tableDesc}列表");
    }

    //新增
    function add${objectName}() {
        var openedFun = function () {};
        var saveFun = function(index, layero) {
            var formEle = layero.find("iframe")[0].contentWindow.$("#formInfo");
            if (formEle.form("validate")) {
                var ${objectName?uncap_first}Info = getFormJson(formEle);
                var successFun = function(bizData) {
                    layer.close(index);
                    query(pageParam, true);
                    showSuccessMsg("新增成功");
                };
                ajaxPostFun("${objectName?uncap_first}/saveInfo", ${objectName?uncap_first}Info, successFun, null, "新建${tableDesc}");
            }
        };
        openIframe(false, 500, 260, "${objectName?uncap_first}-info.html", openedFun, saveFun);
    }

    //修改
    function edit${objectName}() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length != 1) {
            return showWarnMsg("请选择一条条目后操作");
        }
        var openedFun = function (index, layero) {
            var row = copyObj(selectRows[0]);
            $("iframe")[0].contentWindow.$("#formInfo").form("load", row);
        };
        var saveFun = function(index, layero) {
            var formEle = layero.find("iframe")[0].contentWindow.$("#formInfo");
            if (formEle.form("validate")) {
                var ${objectName?uncap_first}Info = getFormJson(formEle);
                var successFun = function(bizData) {
                    layer.close(index);
                    query(pageParam, true);
                    showSuccessMsg("修改成功");
                };
                ajaxPostFun("${objectName?uncap_first}/updateInfo", ${objectName?uncap_first}Info, successFun, null, "修改${tableDesc}");
            }
        };
        openIframe(false, 500, 260, "${objectName?uncap_first}-info.html", openedFun, saveFun);
    }

    //删除
    function del${objectName}() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length == 0) {
            return showWarnMsg("请选择条目后操作");
        }
        var ids = mergedRowCell(selectRows, "id");
        layer.confirm('确认要删除选中的${tableDesc}吗？', function(index) {
            var successFun = function(bizData) {
                showSuccessMsg("已删除"+ bizData +"条数据");
                query(pageParam, true);
            };
            ajaxPostFun("${objectName?uncap_first}/deleteInfoByIds", {ids: ids}, successFun, null, "删除${tableDesc}");
        });
    }
</script> 
</body>
</html>